/*
Copyright (C) Ariff Ehsan, Abdul Hadi Fikri

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*  Author : Ariff Ehsan
 *  Date   : Jan 12, 2010
 */


#include <system.h>

timer_t app_timer;
uint8_t app_count;

void APP_TIMER_run(void);
void APP_LCD162_startdone(error_t);
void APP_KEYPAD_event(uint8_t x, uint8_t y, uint8_t state);

void APP_booted(){
	
	DDRC |= (1<<PC4);
	
	TIMER_reg(&app_timer, APP_TIMER_run);
	TIMER_start(&app_timer, 100);
	
	LCD162_reg(APP_LCD162_startdone);
}

void APP_TIMER_run(void) {
	
	if (++app_count < 10) {
	
		PORTC ^= (1<<PC4);
		TIMER_start(&app_timer, 100);
	}
	else {
		
		PORTC &= ~(1<<PC4);
		LCD162_start();
	}
}

void APP_LCD162_startdone(error_t err) {
	
	//PORTC |= (1<<PC4);
	uint8_t s[] = "ariff@2010";
	
	LCD162_putString(s, sizeof(s) - 1);
	
	//KEYPAD44_init();
	//KEYPAD44_reg(APP_KEYPAD_event);
}

void APP_KEYPAD_event(uint8_t x, uint8_t y, uint8_t state) {
	
	if (state == KEYPAD44_STATE_RELEASED)
		PORTC &= ~(1<<PC4);
	else if (state == KEYPAD44_STATE_PUSHED)
		PORTC |= (1<<PC4);
}

